<?php

namespace app\h5\controller;

use app\admin\model\Bank;
use app\admin\model\Enterprise;
use app\admin\model\hall\Hotmatter;
use app\admin\model\review\Points;
use app\common\library\Upload;
use app\h5\model\FaceLog;
use app\h5\model\Setting;
use app\admin\model\matter\Info;
use ba\Tree;
use Throwable;
use think\facade\Db;
use think\facade\Config;
use app\common\controller\Frontend;
use app\common\library\token\TokenExpirationException;
use \app\admin\model\Hall;

class Index extends Frontend
{
    protected array $noNeedLogin = ['get_bank_list','enterprise_add','get_bank_detail'];

    public function initialize(): void
    {
        parent::initialize();
    }


    /**
     * 企业信息提交
     */
    public function enterprise_add(): void
    {
        $param = $this->request->param();
        if(empty($param['name'])){
            $this->error('请填写企业名称');
        }
        $model = new Enterprise;
        $model->allowField(['name','faren','phone'])->save($param);

        $this->success('提交成功');
    }

    /**
     * 贷款产品列表
     */
    public function get_bank_list(): void
    {
        $list = Bank::order('weigh')->select()->each(function ($item){
            $item->biaoqian = explode(',',$item->biaoqian);
        })->toArray();

        $this->success('成功',$list);
    }

    /**
     * 贷款产品详情
     */
    public function get_bank_detail(): void
    {
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('参数错误');
        }
        $data = Bank::find($id)->toArray();
        $data['tiaojian'] = preg_split("/\n/",$data['tiaojian']);

        $this->success('成功',$data);
    }
}